<template>
  <span>
    <el-button type="primary" size="mini" style="float:right;margin-bottom:5px;margin-left:0px;" icon="el-icon-download" round @click="doExportExcel">导出Excel</el-button>
  </span>
</template>
<script>
import { download } from '@/api/download'
import { Message } from 'element-ui'
import common from '@/api/active-global'
export default {
  props: {
    parent: {
      type: Object,
      default: null
    }
  },
  data() {
    return {
    }
  },
  methods: {
    // 批量导出
    doExportExcel() {
      if (this.parent.ids.length < 1) {
        Message({
          message: '请选择需要导出的item!',
          type: 'error',
          duration: 3 * 1000
        })
      } else {
        this.$confirm('确认导出选择的 ' + this.parent.ids.length + ' 条item信息?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          var uri = common.basePath + '/exportActiveItemExcel'
          var filename = 'active-item.xlsx'
          if (this.parent.changeType === common.itemType) {
            filename = 'change-type-item.xlsx'
          } else if (this.parent.changeType === common.itemStatus) {
            filename = 'active-item.xlsx'
          }
          console.log('filename:' + filename)
          download(uri, { ids: this.parent.ids }, filename)
        })
      }
    }
  }
}
</script>
